package org.light.framework.aop;

import java.lang.reflect.Method;

/**
 * 切面代理抽象类
 * @author de.cel
 *
 */
public abstract class AspectProxy implements Proxy {

	@Override
	public final Object doProxy(ProxyChain proxyChain) throws Throwable {

		Object result = null;

		Class<?> type = proxyChain.getTargetClass();
		Method method = proxyChain.getTargetMethod();
		Object[] methodParams = proxyChain.getMethodParams();

		begin();
		try {

			if (intercept(type, method, methodParams)) {
				before(type, method, methodParams);
				result = proxyChain.doProxyChain();
				after(type, method, methodParams,result);
			} else {
				result = proxyChain.doProxyChain();
			}

		} catch (Exception e) {
			error(type, method, methodParams, e);
		} finally {

			end();
		}
		return result;
	}

	public void error(Class<?> type, Method method, Object[] methodParams, Exception e) {
		// TODO Auto-generated method stub

	}

	public void after(Class<?> type, Method method, Object[] methodParams,Object result) throws Throwable {
		// TODO Auto-generated method stub

	}

	public void before(Class<?> type, Method method, Object[] methodParams)throws Throwable {
		// TODO Auto-generated method stub

	}

	public boolean intercept(Class<?> type, Method method, Object[] methodParams) {
		// TODO Auto-generated method stub
		return true;
	}

	public void end() {
		// TODO Auto-generated method stub

	}

	public void begin() {
		// TODO Auto-generated method stub
	}
}
